<?php

class Core_User extends Zend_Db_Table_Abstract {

    protected $_name = 'user';

    /*
     * Get all users
     */

    public function getAll($where = "",$order = "") {

        $select = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('u' => 'user'))
                        ->join(array('tu' => 'db_roles'), 'u.id_role = tu.id', 'tu.role');

        if (!empty($where))
            $select->where($where);

        if (!empty($order))
            $select->order($order);
        return $this->_fetch($select);
    }

    /*
     * Get a single user by ID
     */

    public function getUserByID($id) {
        $select = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('u' => 'user'))
                        ->join(array('tu' => 'db_roles'), 'u.id_role = tu.id', 'tu.role')
                        ->where('u.id = ? ', $id);
        return $this->_fetch($select);
    }

    /*
     * Insert a New user
     */

    public function insertUser($data) {
        $this->_db->insert('user', $data);
    }

    /*
     * Edit a User
     */

    public function updateUser($id, $data) {
        $this->_db->update('user', $data, 'id = ' . $id);
    }

    /*
     * Delete User
     */

    public function deleteUser($id) {
        $this->_db->delete('user', 'id = ' . $id);
    }

}